package org.tourism.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.tourism.common.CommonResponse;
import org.tourism.service.impl.OssService;

import java.io.IOException;

@RestController
@RequestMapping("/upload")
public class ImageController {

    @Autowired
    OssService ossService;

    @PostMapping
    public CommonResponse upload(@RequestPart("file") MultipartFile file) throws IOException {
        String savePath = "test/test2.jpg";
        String imageUrl = ossService.uploadImage(file, savePath);
        ossService.saveImage(imageUrl);
        return CommonResponse.createForSuccess();
    }
}
